package com.wardrobe.soa.api.user;

import com.wardrobe.domain.user.UserFromBean;
import com.wardrobe.domain.user.UserLoginFromBean;
import com.wardrobe.soa.common.ApiResult;
import com.wardrobe.soa.huanxin.HuanXinUtil;
import io.swagger.client.model.User;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by m1304 on 2018/8/6.
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ApiResult saveUser(UserFromBean fromBean){
        return userService.saveUser(fromBean);
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ApiResult getLoginUser(UserLoginFromBean fromBean, HttpServletRequest request){
        return userService.getLoginUser(fromBean.getMobileNumber(),fromBean.getPassword());
    }

    @RequestMapping(value = "/reSet", method = RequestMethod.POST)
    public ApiResult reSet(UserFromBean fromBean){
        return userService.reSet(fromBean);
    }

    @RequestMapping(value = "/send", method = RequestMethod.POST)
    public ApiResult sendPhoneMsgCode(String mobileNumber,int type){
        return userService.sendPhoneMsgCode(mobileNumber,type);
    }
    @RequestMapping("/token")
    public String test() throws Exception {
        User user = new User();
        user.setUsername("test");
        user.password("test");
        String s = HuanXinUtil.registerHuanXin(user);
        return s;
    }
}
